<!-- 注册
 1. vue始终在用双向绑定的思想来准备前后端交互，每一个vue都会定义好变量给 表单（form）或者表格（table）中的html元素的值绑定
-->
<template>
  <div><!-- element组件库的Dialog对话框默认可以通过点击 modal 关闭 Dialog，即点击空白处弹框可关闭。 -->
    <!-- :visible.sync 子组键改变父组件的值 控制子组件的显示-->
    <el-dialog title="你确定要删除吗？" :visible.sync="deleteDialogIsShow" :before-close="handleClose"
               :close-on-click-modal="false">
      <el-form :model="activetyrecord" label-width="80px" ref="deleteActivetyrecordForm">

      </el-form>
      <span>
      <el-button type="success" @click="deleteActivetyrecord('deleteActivetyrecordForm')">确定删除</el-button>
         <el-button type="success" @click="handleClose('deleteActivetyrecordForm')">取消</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import api from "../../../../axios/api"
  import rules from "../../../../static/js/validator/rules.js";

  export default {
    name: "deleteActivetyrecord",
    data() {
      return {
        activetyrecord: {aname: "", aimg: "", astate: "", aphone: "", apwd: ""},
        deleteDialogIsShow: false,
      }
    },
    methods: {
      deleteActivetyrecord: function (deleteActivetyrecordForm) {
        this.$refs[deleteActivetyrecordForm].validate(valid => {//此处refs对象和标签上的ref对应
          if (valid) {

            //如果通过验证 to do...
            //console.log(this.activetyrecord);
            this.setDataFromAxios();
            alert(this.activetyrecord.aname + "删除成功");
            this.handleClose();

          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      //页面初始化时加载的事件
      init(activetyrecord) {
        this.deleteDialogIsShow = true;
        this.activetyrecord = activetyrecord;
        console.log(activetyrecord);
      },

      //关闭页面
      handleClose() {
        this.deleteDialogIsShow = false;
        //给父组件传参
        this.$emit("deleteDialogIsShow", this.deleteDialogIsShow);
      },
      setDataFromAxios: function () {
        // alert(this.activetyrecord.ano);
        //为什么要封装一下方法 1.每个vue组件有自己的一些参数处理，简化调用本来这个setDataFromAxios这个方法属于api 重新封装就属于当前页面
        api.setDataFromAxios(this.$store.state.host + "activetyrecordController/deleteActivetyrecordByAfno/" + this.activetyrecord.afno, null, "post")
          .then(res => {
            console.log(res);
          });//.then方法 就是当服务器有返回的时候执行回调函数，对比jquery的ajax success:function（data）

      },
    },

    //监听
    watch: {
      dialogisShow(newValue, oldValue) {
        this.deleteDialogIsShow = newValue;
      }
    }

  }
</script>

<style scoped>

</style>
